package com.mjlf.mr;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.StringTokenizer;

/**
 * @ClassName: MrMap
 * @Author: majun
 * @CreateDate: 2018/12/14 9:46
 * @Version: 1.0
 * @Description: TODO
 */

public class MrMap extends Mapper<LongWritable, Text, Text, IntWritable> {

    Text text = new Text();
    IntWritable count = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        StringTokenizer stringTokenizer = new StringTokenizer(value.toString());
        while(stringTokenizer.hasMoreElements()){
            text.set(stringTokenizer.nextToken());
            context.write(text, count);
        }
    }
}
